package j2eelogin.persist;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class GroupTest {

	public static void main(String[] args) {
		EntityManagerFactory emFactory =
			Persistence.createEntityManagerFactory("PersistenceManager");
		
		// Java SE bootstrap
		EntityManager em = emFactory.createEntityManager();
		
		em.getTransaction().begin();
		
		Groupe groupe = new Groupe();
		groupe.setName("BigBrother");
		em.persist(groupe);
		
		User ceo = new User();
		ceo.setFirstName("John");
		ceo.setGroup(groupe);
		groupe.getUsers().add(ceo);
		em.persist(ceo);
		
		
		
		User cfo = new User();		
		cfo.setFirstName("Bill");
		cfo.setGroup(groupe);
		groupe.getUsers().add(cfo);
		em.persist(cfo);
		
		em.getTransaction().commit();
		
		em.close();
		
		emFactory.close();

	}
}
